﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Common;
using EntLib.Domain.Model;

namespace EntLib.Domain.DAL
{
    /// <summary>
    /// 订单相关的数据层
    /// </summary>
    public class OrderDA : Base<Order>
    {
        #region 常量定义
        /// <summary>
        /// 表名
        /// </summary>
        static readonly string Table_Name = "[KS_Order]";
        /// <summary>
        /// 排序
        /// </summary>
        static readonly string Order_By = "[Id] DESC";
        /// <summary>
        /// 选取字段
        /// </summary>
        static readonly string Fields = "[ShopId],[OrderId],[UserId],[ProductPrice],[InputTime],[ProductNum],[ProductId],[ProductName],[Status],[LM],[YongJin],[CommissionType],[OrderTime],[MallIdentifier],[IsMaintain]";

        #endregion
      
        /// <summary>
        /// 根据用户指定条件，获取订单分页列表
        /// </summary>
        /// <param name="userId">UserID</param>
        /// <param name="orderId">OrderID</param>
        /// <param name="mallIdentifier">商城标识</param>
        /// <param name="pageindex">索引页</param>
        /// <param name="total">总记录数</param>
        /// <param name="status">状态 - 0:未审核,1:已审核，null则不筛选</param>        
        /// <returns></returns>
        public List<Order> GetOrderPagingList(int userId, string orderId, string mallIdentifier, int pageIndex, out int total, int? status)
        {
            string where = string.Empty;
            if (userId > 0)
            {
                where = string.Format("[UserId] = {0} ", userId);
                if (status != null)
                {
                    where += string.Format("AND [Status] = {0} ", status);
                }
            }
            if (!string.IsNullOrEmpty(orderId))
            {
                where = string.Format("[OrderId] = '{0}' ", orderId);
            }
            if (!string.IsNullOrEmpty(mallIdentifier))
            {
                where = string.Format("[MallIdentifier] = '{0}' ", mallIdentifier);
            }
            return base.GetPageDetail(db, Table_Name, Fields, Order_By, where, 20, pageIndex, out total);
        }
    }
}
